/**
 * @param {number[][]} coordinates
 * @return {boolean}
 */
export var checkStraightLine = function (coordinates) {
  const [dx, dy] = coordinates[0]
  // 移动曲线，使第一点起点为原点
  for (let i = 1; i < coordinates.length; i++) {
    const [x, y] = coordinates[i]
    coordinates[i] = [x - dx, y - dy]
  }
  const [x1, y1] = coordinates[1]
  for (let i = 2; i < coordinates.length; i++) {
    const [x, y] = coordinates[i]
    if (x1 * y !== x * y1) {
      return false
    }
  }
  return true
}

export var checkStraightLine2 = function (coordinates) {
  const n = coordinates.length
  let m = ''
  for (let i = 0; i < n - 1; i++) {
    const [x1, y1] = coordinates[i]
    const [x2, y2] = coordinates[i + 1]
    let k = x1 === x2 ? null : (y1 - y2) / (x1 - x2)
    if (m === '') {
      m = k
    }
    if (k !== m) {
      return false
    }
  }
  return true
}
